package com.example.demo;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.moonshot.MoonshotChatModel;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Config {



    @Resource
    private MoonshotChatModel moonshotChatModel;

    @Bean
    public ToolCallbackProvider userTools(UserService userService) {
        return MethodToolCallbackProvider.builder().toolObjects(userService).build();
    }


    @Bean
    public ChatClient chatClient(UserService userService) {
        MethodToolCallbackProvider build = MethodToolCallbackProvider.builder().toolObjects(userService).build();
        return ChatClient.builder(moonshotChatModel).defaultTools(build.getToolCallbacks()).build();
    }



}
